
class Student(object):
    def __init__(self):
        super().__init__()
        self.student_list = []

    def print_menu(self):
        print("="*50)
        print("\t~学生管理系统1.0版本~")
        print("\t1:添加学生信息")
        print("\t2:删除学生信息")
        print("\t3:修改学生信息")
        print("\t4:查找学生信息")
        print("\t5:显示学生信息")
        print("\t6:退出学生信息系统")
        print("="*50)
        print("\n")


    def add_info(self):
        # 定义一个字典
        student = {}
        name = input("请输入要添加的学生姓名：")
        phone = input("请输入要添加的学生电话：")
        wechat = input("请输入要添加的学生微信：")
        # 往字典里添加数据
        student["name"] = name
        student["phone"] = phone
        student["wechat"] = wechat
        # 把学生字典添加到列表中
        # student_list.insert(0, student)
        self.student_list.append(student)

        print(self.student_list)
        # 打印信息
        self.show_info()

    def show_info(self):
        print("\n")
        print("\t\t当前学生信息")
        print("~"*70)
        print("\t姓名\t\t电话\t\t微信\t")
        for student in self.student_list:
            print("\t" + student["name"] + "\t\t" + student["phone"] + "\t\t" + student["wechat"] + "\t")
        print("~"*70)
        print("\n")


    def del_info(self):
        "删除学生信息的方法"
        name = input("请输入要删除的学生姓名：")
        for student in self.student_list:
            if name == student["name"]:
                student_list.remove(student)
        # 查看学生信息
        self.show_info()

    def mod_info(self):
        name = input("请输入要修改的学生姓名：")
        for student in self.student_list:
            if name == student["name"]:
                # 输入新的学生信息
                new_name = input("请输入新的学生姓名：")
                new_phone = input("请输入新的学生电话：")
                new_wechat = input("请输入新的学生微信：")
            student["name"] = new_name
            student["phone"] = new_phone
            student["wechat"] = new_wechat
            # 查看学生信息
            self.show_info()

    def find_info(self):
        name = input("请输入要修改的学生姓名：")
        flag = False
        for student in self.student_list:
            if name == student["name"]:
                print("已经查询到%s" % name)
                flag = True
            
        if flag == False:
            print("没有查询到%s" % name)
            
    def save_data(self):
        # 添加、删除、修改时保存信息
        # 在程序运行时读取信息
        f = open("stu.data", "w")
        f.write(str(self.student_list))
        f.close


    def read_data(self):

        f = open("stu.data", "a+")
        f.seek(0)
        content = f.read()
        print(content)
        if len(content) > 0:
            self.student_list = eval(content)
        f.close()



    def main(self):
        self.print_menu()
        self.read_data()
        print("\n")
        while True:
            print("\t\t操作指令")
            print("~"*50)
            infos =  "1:增加|2:删除|3:修改|4:查找|5:显示|6:退出系统"
            print(infos)
            print("~"*50)
            num = input("请按照上面的提示输入相应指令：")
            # print(num)
            # 判断用户输入的内容:1、2、3、4、5、6
            if num == "1":
                print("添加")
                self.add_info()
                self.save_data()
            elif num == "2":
                print("删除")
                self.del_info()
                self.save_data()
            elif num == "3":
                print("修改")
                self.mod_info()
                self.save_data()
            elif num == "4":
                print("查询")
                self.find_info()
            elif num == "5":
                print("显示")
                self.show_info()
            elif num == "6":
                print("退出")
                break

# 调用main方法
stu = Student()
stu.main()